<template>
  <view>
    <!-- 选择收货地址的盒子 -->
    <view v-if="JSON.stringify(address) ==='{}'">
      <view class="address-choose-box">
        <button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址+</button>
      </view>
    </view>
    <view v-else @click="chooseAddress">
      <view class="address-top">
        <!-- 收货人 -->
        <view class="address-name">
          收货人：<text>{{address.userName}}</text>
        </view>
        <!-- 电话号 -->
        <view class="address-phone">
          电话：<text>{{address.telNumber}}</text>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
      </view>


      <view class="address-under">
        <!-- 收货地址 -->
        收货地址：<text>{{addstr}}</text>
      </view>
    </view>

    <view class="line11">-----------------------------------------------------</view>

  </view>
</template>

<script>
  import {
    mapState,
    mapMutations,
    mapGetters
  } from 'vuex'
  export default {
    name: "my-address",
    data() {
      return {
        // address: {}
      };
    },
    computed: {
      ...mapState('m_user', ['address']),
      ...mapGetters('m_user', ['addstr']),
    },

    methods: {
      ...mapMutations('m_user', ['updateAddress']),
      async chooseAddress() {
        const [err, succ] = await uni.chooseAddress().catch(err => err)
        if (err === null && succ.errMsg === 'chooseAddress:ok') {
          console.log(succ);
          this.updateAddress(succ)
          // this.address = succ
        }
      }
    }
  }
</script>

<style lang="scss">
  .address-choose-box {
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .address-top {
    display: flex;
    justify-content: space-between;
    padding: 10px 5px;

    .address-name {}

    .address-phone {
      margin-left: 70px;
    }
  }

  .address-under {
    padding: 10px 5px;
    // display: flex;
    // align-items: center;
  }

  .line11 {
    color: red;
    font-weight: bold;
  }
</style>
